Graficación en ggplot2 y quarto

Introducción

Este documento presenta un conjunto visualizaciones de datos elaborados de datos elaborados con paquetes del lenguaje R como ggplot, plotly y DT

#Carga de bibliotecas

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
library(DT)
library(gapminder)

#carga de datos

#| label: carga-datos-mpg
#| warning: false
#| code-fold: true
mpg |>
  datatable()
    options = list(
      pageLength = 5,
      language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
    )

diamons

#| label: carga-datos-diamonds
#| warning: false
#| code-fold: true
diamonds |>
  datatable()
Warning in instance$preRenderHook(instance): It seems your data is too big for
client-side DataTables. You may consider server-side processing:
https://rstudio.github.io/DT/server.html
    options = list(
      pageLength = 5,
      language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
    )

##gapminder

#| label: carga-datos-gapminder
#| warning: false
#| code-fold: true
gapminder |>
  filter(year == 2007) |>
  datatable()
    options = list(
      pageLength = 5,
      language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
    )

COVID

Código
# Carga del archivo CSV de entrada en un dataframe
# con la función read_delim() de readr
covid_general <-
  read_delim(
    file = "https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2023-i/main/datos/ministerio-salud/covid/05_30_22_CSV_GENERAL.csv",
    col_select = c(
      "FECHA",
      "positivos",
      "activos",
      "RECUPERADOS",
      "fallecidos",
      "nue_posi",
      "nue_falleci",
      "salon",
      "UCI"
    )
  )

# Cambio de nombre de columnas
covid_general <-
  covid_general |>
  rename(
    fecha = FECHA,
    recuperados = RECUPERADOS,
    nuevos_positivos = nue_posi,
    nuevos_fallecidos = nue_falleci,
    uci = UCI
  )

# Cambio de tipo de datos de la columna fecha, de str a date
covid_general <-
  covid_general |>
  mutate(fecha = as.Date(fecha, format = "%d/%m/%Y"))

# Despliegue de datos
covid_general |>
  datatable()
Código
    options = list(
      pageLength = 5,
      language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
    )

Delitos

Código
# Carga de datos
delitos_2022 <-
  read_delim(
    file = "https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2023-i/main/datos/oij/estadisticas-policiales/estadisticaspoliciales2022.csv"
  )

# Tabla de datos
delitos_2022 |>
  datatable(
    options = list(
      pageLength = 5,
      language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
    )
  )